package com.linhz.demo09.Lock;

import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.Lock;
public class RunnableImpl implements Runnable{
    private int ticket = 100;

    Lock l = new ReentrantLock();

    @Override
    public void run() {
        while(true){
            l.lock();
            if (ticket>0){
                try{
                    Thread.sleep(10);
                    System.out.println(Thread.currentThread().getName()+"-->正在卖"+ticket+"张票");
                    ticket--;
                }catch (InterruptedException e){
                    e.printStackTrace();
                }finally {
                    l.unlock();
                }

            }
        }
    }
}
